home *** CD-ROM | disk | FTP | other *** search
- set output error
-
- display _new in blue /*
- */ "Loading Graph.Kit Release 2.0 Demonstration Version" _n /*
- */ "Copyright (c) 1987-1988 by ==C=R=C==. All rights reserved."
-
-
-
- /*
- User's wishing to edit Graph.Kit please see comments at end of this file.
- */
-
-
- /*
- utility routines used by qqplot
- */
-
- capture program drop _qqalign
- program define _qqalign
- capture {
- sort %_1
- gen _YORDER=_n
- sort %_2
- gen %_3=%_2[_YORDER]
- drop _YORDER
- exit
- }
- capture drop _YORDER
- BREAK
- end
-
- * _qqcomp varname old# new#
-
- capture program drop _qqcomp
- program define _qqcomp
- capture {
- sort %_1
- gen int _INT=(_n-0.5)*%_2/%_3+0.5
- gen _FRAC=0.5+(_n-0.5)*%_2/%_3-_INT
- gen _TEMP=(1-_FRAC)*%_1[_INT]+_FRAC*%_1[_INT+1]
- replace %_1=_TEMP
- drop _INT _FRAC _TEMP
- exit
- }
- capture drop _INT
- capture drop _FRAC
- capture drop _TEMP
- BREAK
- end
-
- * utility routines
-
- capture program drop _setlbl
- program define _setlbl
- mac def _w : variable label %_2
- if "%_w"=="" {
- mac def _w "%_2"
- }
- label variable %_1 "%_w"
- end
-
- capture program drop _nmusig2
- program define _nmusig2
- capture {
- sum %_1 %_5 %_6
- gen int %_2 = _result(1) in l
- gen double %_3 = _result(3) in l
- gen double %_4 = _result(4) in l
- exit
- }
- capture drop %_2
- capture drop %_3
- capture drop %_4
- BREAK
- end
-
- capture program drop _chkstr
- program define _chkstr
- mac def _if "opt"
- noisily parse "%_*"
- end
-
-
- * new commands
-
- capture program drop symplot
- program define symplot
- if "%_*"=="" {
- di in bl "-> symplot varname [if] [in] [, graph_options]"
- exit
- }
- mac def _varlist "req ex max(1)"
- mac def _if "opt"
- mac def _in "opt"
- mac def _options "*"
- parse "%_*"
- capture {
- gen double _VAR = %_varlist %_if %_in
- sort _VAR
- gen int _CNT=sum(_VAR~=.)
- if _CNT[_N]==0 {
- drop _VAR _CNT
- di in red "no observations"
- exit
- }
- mac def _midpt = int(_CNT[_N]+1)/2
- #delimit ;
- mac def _median=cond(int(_CNT[_N]/2)*2==_CNT[_N],
- (_VAR[%_midpt]+_VAR[%_midpt+1]) / 2,
- _VAR[%_midpt]) ;
- #delimit cr
- gen _BELOW=_VAR-(%_median)
- drop _VAR
- sort _BELOW
- gen _ABOVE=_BELOW[_CNT[_N]+1-_n]
- replace _BELOW=abs(_BELOW)
- gen _LINE=_BELOW
- lab var _LINE " "
- lab var _BELOW "Distance below median"
- lab var _ABOVE "Distance above median"
- mac def _w : variable label %_varlist
- if "%_w"=="" {
- mac def _w "%_varlist"
- }
- graph _ABOVE _LINE _BELOW if _n<=%_midpt, /*
- */ sy(oi) c(.l) sort %_options t2("%_w")
- }
- if _rc {
- di in red "--Break--"
- }
- capture drop _VAR
- capture drop _ABOVE
- capture drop _BELOW
- capture drop _LINE
- capture drop _CNT
- end
-
-
- capture program drop quantile
- program define quantile
- if "%_*"=="" {
- di in bl "-> quantile varname [if] [in] [, graph_options]"
- exit
- }
- mac def _varlist "req ex max(1)"
- mac def _if "opt"
- mac def _in "opt"
- mac def _options "*"
- parse "%_*"
- capture {
- gen _QUANT=%_varlist %_if %_in
- sort _QUANT
- gen int _CNT=sum(_QUANT~=.)
- gen _FRAC=(_CNT-0.5)/_CNT[_N]
- gen _LINE=_QUANT[1]+_CNT*((_QUANT[_CNT[_N]]-_QUANT[1])/_CNT[_N])
- _setlbl _QUANT %_varlist
- mac def _w : variable label _QUANT
- lab var _QUANT "Quantiles of %_w"
- lab var _FRAC "Fraction of the data"
- lab var _LINE " "
- #delimit ;
- graph _QUANT _LINE _FRAC, s(oi) c(.l) xsca(0,1)
- %_options xlab(0,.25,.5,.75,1) ;
- #delimit cr
- }
- if _rc {
- di in red "--Break--"
- }
- capture drop _QUANT
- capture drop _LINE
- capture drop _FRAC
- capture drop _CNT
- end
-
- capture program drop qqplot
- program define qqplot
- if "%_*"=="" {
- di in bl "-> qqplot yvar xvar [if] [in] [, graph_options]"
- exit
- }
- mac def _varlist "req ex min(2) max(2)"
- mac def _if "opt"
- mac def _in "opt"
- mac def _options "*"
- parse "%_*"
- parse "%_varlist", parse(" ")
- capture {
- gen _VARY=%_1 %_if %_in
- gen _VARX=%_2 %_if %_in
- gen int _CNT=sum(_VARY~=.)
- mac def _cnty=_CNT[_N]
- replace _CNT=sum(_VARX~=.)
- mac def _cntx=_CNT[_N]
- drop _CNT
- if %_cntx==0 | %_cnty==0 {
- drop _VARY _VARX
- di in red "no observations"
- exit
- }
- if %_cnty>%_cntx {
- _qqcomp _VARY %_cnty %_cntx
- }
- if %_cnty<%_cntx {
- _qqcomp _VARX %_cntx %_cnty
- }
- _qqalign _VARY _VARX _NEWX2
- _setlbl _VARY %_1
- _setlbl _NEWX2 %_2
- #delimit ;
- noisily graph _VARY _NEWX2 _NEWX2, %_options
- ti(" Quantile-Quantile Plot") sy(oi) c(.l) sort;
- #delimit cr
- drop _NEWX2 _VARY _VARX
- exit
- }
- di in red "--Break--"
- capture drop _CNT
- capture drop _NEWX2
- capture drop _VARY
- capture drop _VARX
- end
-
- capture program drop qnorm
- program define qnorm
- if "%_*"=="" {
- di in bl "qnorm varname [if] [in] [, graph_options]"
- exit
- }
- mac def _varlist "req ex max(1)"
- mac def _if "opt"
- mac def _in "opt"
- mac def _options "*"
- parse "%_*"
- capture {
- gen _UVAR=%_varlist %_if %_in
- sort _UVAR
- _nmusig2 _UVAR _CNT _MEAN _STD
- if _CNT[_N]==0 {
- drop _UVAR _CNT _MEAN _STD
- di in blue "no observations"
- exit
- }
- replace _STD=sqrt(_STD) in l
- gen _NORM=invnorm((_n-.5)/_CNT[_N])*_STD[_N]+_MEAN[_N] /*
- */ if _UVAR~=.
- drop _CNT _MEAN _STD
- _setlbl _UVAR %_varlist
- label var _NORM "Normal"
- }
- if _rc {
- di in red "--Break--"
- capture drop _UVAR
- capture drop _CNT
- capture drop _MEAN
- capture drop _STD
- capture drop _NORM
- exit
- }
- qqplot _UVAR _NORM, %_options
- drop _NORM _UVAR
- end
-
-
- capture program drop grebar
- program define grebar
- di in blue "not available in demonstration version"
- end
-
- capture program drop leverage
- program define leverage
- if "%_*"=="" {
- di in blu /*
- */ "->leverage lhs rhs other-rhs-vars [if] [in] [, graph_options]"
- exit
- }
- mac def _varlist "req ex"
- mac def _options "*"
- mac def _in "opt"
- mac def _if "opt"
- parse "%_*"
- parse "%_varlist", parse(" ")
- mac def _lhs %_1
- mac def _rhs %_2
- mac shift
- mac shift
- capture {
- reg %_lhs %_* %_if %_in, noo
- predict _RESID1 %_if %_in, resid
- reg %_rhs %_* %_if %_in, noo
- predict _RESID2 %_if %_in, resid
- reg _RESID1 _RESID2, noo
- predict _PREDL %_if %_in
- _setlbl _RESID1 %_lhs
- _setlbl _RESID2 %_rhs
- lab var _PREDL " "
- #delimit ;
- noisily graph _RESID1 _PREDL _RESID2, s(oi) c(.l) sort
- %_options
- title(" Partial Regression Leverage Plot");
- #delimit cr
- }
- if _rc==1 {
- di in red "--Break--"
- }
- capture drop _RESID1
- capture drop _RESID2
- capture drop _PREDL
- end
-
-
- capture program drop hilite
- program define hilite
- if "%_*"=="" {
- di in bl "->hilite yvar xvar [if] [in], hilite(exp) [graph_options]"
- exit
- }
- mac def _varlist "req ex min(2) max(2)"
- mac def _if "opt"
- mac def _in "opt"
- mac def _options "Hilite(string) Symbol(string) *"
- parse "%_*"
- if "%_hilite"=="" {
- hilite
- }
- capture _chkstr if %_hilite
- if _rc {
- exit
- }
- parse "%_varlist", parse(" ")
- if "%_symbol"=="" {
- mac def _symbol ".o"
- }
- capture {
- gen _Temp = %_1 if %_hilite %_in
- mac def _w : variable label %_1
- if "%_w"=="" {
- mac def _w "%_1"
- }
- capture noisily graph %_1 _Temp %_2 %_if %_in, s(%_symbol) /*
- */ t1("%_hilite highlighted") l1("%_w") %_options
- capture {
- drop _Temp
- exit
- }
- }
- di in red "--Break--"
- capture drop _Temp
- end
-
-
-
- di
- di in gr "The following new commands are now available:"
- di " grebar leverage qqplot quantile symplot"
- di " hilite qnorm"
-
-
- di _n in gr "See " in wh "help graph.kit" in gr "."
- exit
-
- Notes to User's wishing to edit this file:
-
- These comments are placed at the end of the file, after the exit, so that
- Stata does not have to read through them every time the user types "run
- Graph.Kit"
-
- Feel free to edit this file and delete programs in which you have no interest.
- Before editing this file, however, make sure the the original is BACKED UP.
- Please do not remove the copyright notice at the top of this file.
-
- If you do edit the file, you should add a display command at the top of this
- file indicating that you have edited the file. You should change the display
- just above these comments that lists the new commands now available.
-
- All utility programs start with an underscore '_'.
-
- Some programs use other programs in achieving the desired result. Review the
- table below carefully before deleting programs.
-
- Program Requires
- --------------------------
- grebar
- hilite _chkstr
- leverage _setlbl
- qnorm _setlbl _nmusig2 qqplot
- qqplot _setlbl _qqalign _qqcomp
- quantile _setlbl
- symplot
-
- For instance, if you deleted the _setlbl program, you would break leverage,
- qnorm, qqplot, and quantile.
-
- <end of Graph.Kit>